<?php

namespace App\Models;


class BlackAccount extends CommonModel
{
    //
    protected $table = 'account_blacklist';

    /**
     * 关联操作员信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    /**
     * 判断是否已经存在有效的黑名单记录
     *
     * @param $account_no
     * @param int $id
     * @return bool
     */
    public static function isExist($account_no, $id = 0)
    {
        $data = self::where(['account_no' => $account_no, 'is_delete' => 0])->when($id, function ($query) use ($id) {
            $query->where('id', '!=', $id);
        })->first();
        return is_null($data) ? false : true;
    }
}
